from threading import RLock
mutex = RLock()
# mutex.acquire()
# print("执行代码内容1")
# mutex.acquire()
# print("执行代码内容2")
# mutex.release()
# mutex.release()

with mutex:
    with mutex:
        print("执行代码内容1")